﻿
// Condition: 8. Write a method that adds two positive integer numbers represented as arrays of digits
//               (each array element arr[i] contains a digit; the last digit is kept in arr[0]). 
//               Each of the numbers that will be added could have up to 10 000 digits.


using System;



class SumTwoBigInteg
{
    // this method will present number on string format to hold more digits
    static string Sum(string num1, string num2)
    {
        // find bigger length of two numbers in string format
        int maxLength = num1.Length;
        if (num2.Length > num1.Length)
        {
            maxLength = num2.Length;
        }

        // initiate two arrays than will hold all digits of two numbers
        int[] arrayNum1 = new int[maxLength];
        int[] arrayNum2 = new int[maxLength];

        for (int i = 0; i < num1.Length; i++)
        {
            arrayNum1[i] = Convert.ToInt32(Convert.ToString(num1[num1.Length - 1 - i]));
        }

        for (int i = 0; i < num2.Length; i++)
        {
            arrayNum2[i] = Convert.ToInt32(Convert.ToString(num2[num2.Length - 1 - i]));
        }

        // sum of two arrays
        int[] sumArray = new int[maxLength];

        for (int i = 0; i < maxLength; i++)
        {
            if (i == 0)
            {
                sumArray[i] = (arrayNum1[i] + arrayNum2[i]) % 10;
            }
            else
            {
                sumArray[i] = (arrayNum1[i] + arrayNum2[i]) % 10 +
                                (arrayNum1[i - 1] + arrayNum2[i - 1]) / 10;
            }
        }

        // return the sum in string order
        string final = null;

        for (int i = maxLength - 1; i >= 0; i--)
        {
            final += Convert.ToSingle(sumArray[i]);
        }
        return final ;

    }


    static void Main(string[] args)
    {

        // input information about two numbers
        Console.WriteLine("Enter two integers to calculate the sum.");
        Console.Write("Enter first integer: ");
        string number1 = Console.ReadLine();
        Console.Write("Enter second integer: ");
        string number2 = Console.ReadLine();


        // print the sum
        Console.WriteLine("The sum of {0}+{1} = {2}",number1,number2,Sum(number1,number2));
    }
}

